<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {$LOAD_STYLE.top|raw}
</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body type-box">
                <button class="pear-btn pear-btn-md" id="settype">
                  批量修改分类
                  <i class="layui-icon layui-icon-down layui-font-12"></i>
                </button>
				<a class="pear-btn pear-btn-md pear-btn-primary" data-id="0">
				    <i class="layui-icon layui-icon-spread-left"></i>
				    全部产品
				</a>
				{volist name="type_list.data" id="v"}
				<a class="pear-btn pear-btn-md" data-id="{$v.id}">
					<i class="layui-icon layui-icon-spread-left"></i>
					{$v.name}
				</a>
				{/volist}
			</div>
			
			<div class="layui-card-body">
				<form class="layui-form layui-form-pane" action="" style="margin-top: 0px;">
					<div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="number" placeholder="" class="layui-input" focus-select>
                    </div>
                </div>
               <div class="layui-form-item layui-inline">
                   <label class="layui-form-label">品名</label>
                   <div class="layui-input-inline">
                       <input type="text" name="title" placeholder="" class="layui-input">
                   </div>
               </div>    
               <div class="layui-form-item layui-inline">
                   <label class="layui-form-label">供应编号</label>
                   <div class="layui-input-inline">
                       <input type="text" name="onumber" placeholder="" class="layui-input">
                   </div>
               </div>
                        <div class="layui-form-item layui-inline">
                       <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="query">
                           <i class="layui-icon layui-icon-search"></i>
                           查询
                       </button>
                       <button type="reset" class="pear-btn pear-btn-md">
                           <i class="layui-icon layui-icon-refresh"></i>
                           重置
                       </button>
                       </div>
                    </div>
				</form>
			</div>
		</div>
		
		<div class="layui-card">
			
		</div>
		
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="dataTable" lay-filter="dataTable"></table>
			</div>
		</div>

		<script type="text/html" id="toolbar">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		        <i class="layui-icon layui-icon-add-1"></i>
		        新增
			</button>
			<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		        <i class="layui-icon layui-icon-delete"></i>
		        删除
		    </button>
            <button class="pear-btn pear-btn-md" lay-event="recycle">
		        <i class="layui-icon layui-icon-delete"></i>
		        回收站
		    </button>
			
			<button class="pear-btn pear-btn-ext1 pear-btn-md toolbar-btn-left" lay-event="cloth_label">
				<i class="layui-icon layui-icon-note"></i>
				打印标签
			</button>
			
			<button class="pear-btn pear-btn-md" lay-event="copy">
			    <i class="layui-icon layui-icon-file-b"></i>
			    复制产品
			</button>
		</script>

        
	   <script type="text/html" id="status">
		   <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="status" {{# if(d.status==1){ }} checked {{# } }}>
	   </script>
	   
	   <script type="text/html" id="issend">
	   		   <input type="checkbox" name="issend" value="{{d.id}}" lay-skin="switch" lay-text="寄过|未寄" lay-filter="issend" {{# if(d.issend==1){ }} checked {{# } }}>
	   </script>
	   
	   <script type="text/html" id="sequence">
	   		   <input type="checkbox" name="sequence" value="{{d.id}}" lay-skin="switch" lay-text="一样|打乱" lay-filter="sequence" {{# if(d.sequence==1){ }} checked {{# } }}>
	   </script>
	   
		<script type="text/html" id="options">
		
		{if isMobile()}
		<div class="layui-row">
			<div class="layui-col-xs10">
			  【{{ d.number }}】
			</div>
			<div class="layui-col-xs2 layui-right">
			  {{# if(d.status==1){ }}
			  <span class="layui-tag pear-btn-green">启用</span>
			  {{# }else{ }}
			  <span class="layui-tag pear-btn-grey">禁用</span>
			  {{# } }}
			</div>
		</div>
		<div class="layui-row">
			<div class="layui-col-xs12">
				{{ d.title }}
			</div>
		</div>
		<div class="layui-row">
			<div class="layui-col-xs5">
				幅宽：{{ d.breadth }}cm
			</div>
			<div class="layui-col-xs4">
				克重：{{ d.square }}g
			</div>
			<div class="layui-col-xs3">
				价格：{{ d.price1 }}元
			</div>
		</div>
		{/if}
		
		<div class="layui-options">
			<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit" title="编辑"><i class="layui-icon layui-icon-edit"></i></button>
			<button class="pear-btn pear-btn-cyan pear-btn-sm" lay-event="import" title="导入面料管理"><i class="layui-icon layui-icon-senior"></i></button>
		    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove" title="删除"><i class="layui-icon layui-icon-delete"></i></button>
		</div>
		</script>

		<script type="text/html" id="alibabaID">
		  {{#  if(d.alibaba_id !=''){ }}
		    <i class="pear-icon pear-icon-link layui-font-red" style="font-size: 24px!important;"></i>
		  {{#  } else { }}
		    <i class="pear-icon pear-icon-link" style="font-size:24px!important;"></i>
		  {{#  } }}
		</script>
		
        <script>
        layui.use(['jquery','common','mycomm','table'], function() {
            let $ = layui.jquery;
			let common = layui.common;
			let mycomm = layui.mycomm;
			let table = layui.table;
			let $table_name = "dataTable";
            let MODULE_PATH = "{$MODULE_PATH}";
            
			{if isMobile()}
			let cols = [
			    [
					{
						title: '操作',
						toolbar: '#options',
						unresize: true,
						align: 'left',
			        }
			    ]
			];
			{else/}
            let cols = [
                [{
						type: 'checkbox',
						fixed: 'left',
					}, {
						field: "number",
						fixed: 'left',
						title: "编号",
						width: 80,
						unresize: "true",
						align: "center",
					}, {
						field: "id",
						title: "ID",
						width: 70,
						sort:	true,
						hide: true,
						unresize: "true",
						align: "center",
					}, {
						field: "type",
						title: "分类名",
						width: 100,
						hide: true,
						unresize: "true",
						align: "center",
					}, {
						field: "supplier",
						title: "供货商",
						width: 100,
						unresize: "true",
						align: "center",
					}, {
						field: "onumber",
						title: "供货编号",
						width: 100,
						unresize: "true",
						align: "center",
					}, {
						field: "title",
						title: "品名",
						width: 180,
						unresize: "true",
						align: "left",
					}, {
						field: "breadth",
						title: "幅宽",
						width: 80,
						templet: "<div>{{d.breadth}}cm</div>",
						unresize: "true",
						align: "center"
					}, {
						field: "square",
						title: "克重",
						width: 80,
						templet: "<div>{{d.square}}g</div>",
						unresize: "true",
						align: "center"
					}, {
						field: "price1",
						title: "售价",
						width: 70,
						edit: 'text',
						unresize: "true",
						align: "center"
					}, {
						field: "price4",
						title: "米价",
						width: 70,
						edit: 'text',
						unresize: "true",
						align: "center",
					}, {
						field: "space4",
						title: "进米价",
						width: 70,
						edit: 'text',
						hide: "false",
						unresize: "true",
						align: "center"
					}, {
						field: "space1",
						title: "供货",
						width: 70,
						edit: 'text',
						unresize: "true",
						align: "center"
					}, {
						field: "tube",
						title: "纸管+空差",
						width: 100,
						templet: "<div>{{d.tube}} + {{d.emptykg}}</div>",
						unresize: "true",
						align: "center",
					}, {
						field: "sort",
						title: "排序",
						width: 80,
						sort: true,
						edit: 'text',
						hide: true,
						unresize: "true",
						align: "center",
					}, {
						field: "remark",
						title: "备注",
						width: 180,
						edit: 'text',
						unresize: "true",
						align: "center",
					}, {
						field: "status",
						title: "状态",
						width: 100,
						unresize: "true",
						align: "center",
						templet:"#status"
					}, {
						field: "issend",
						title: "是否寄样",
						width: 100,
						unresize: "true",
						align: "center",
						templet:"#issend"
					}, {
						field: "sequence",
						title: "色卡顺序",
						width: 100,
						unresize: "true",
						align: "center",
						templet:"#sequence"
					}, {
						title: '操作',
						fixed: 'right',
						toolbar: '#options',
						width: 150,
						unresize: true,
						align: 'center',
					}
                ]
            ]			
			{/if}
			
			mycomm.tableRender('{$controller_title}',MODULE_PATH,cols,{},$table_name);
			mycomm.tableTool('{$controller_title}',MODULE_PATH,$table_name);
			mycomm.search_table($table_name);
			mycomm.tableSetVal(MODULE_PATH);
			mycomm.formSwitch('status',MODULE_PATH);
			mycomm.formSwitch('issend',MODULE_PATH);
			mycomm.formSwitch('sequence',MODULE_PATH);
			
			mycomm.tableToolBar('{$controller_title}',MODULE_PATH,$table_name,function(obj){
				if(obj.event === "cloth_label"){
					let data = table.checkStatus($table_name).data;
					if (data.length === 0) {
						Alert('未选中数据','info',1.5);
						return false;
					}
					var ids = [];
					var hasCheck = table.checkStatus($table_name)
					var hasCheckData = hasCheck.data
					if (hasCheckData.length > 0) {
						$.each(hasCheckData, function (index, element) {
							ids.push(element.id)
						})
					}
					ids=ids.join('|');
					var url="{:U('cloth.temp/label',['type'=>'cloth','id'=>''])}"+ids;
					mycomm.tool_pop(url,'产品标签',0.8);
				}else if(obj.event === "copy"){
					var ids=isSelect(table,$table_name);
					if(ids){
						// load_show('复制数据中...');
						copyCloth(ids);
					}else{
						return false;
					}
				}
			});
			
			mycomm.tableTool('{$controller_title}',MODULE_PATH,$table_name,function(obj){
				if(obj.event === 'import'){
					confirmed('确定把【'+obj.data.number+'】转入面料库吗？',function(){
						var url="{:U('cloth.temp/import')}";
						var data={
							id:obj.data.id
						};
						$.post(url,data,function(res){
							if(res.code==200){
								Alert('导入成功！','success',1);
								table.reload($table_name);
								
							}
						});
					});
				}
			});
			
			// 是否选中产品
			function isSelect(table,table_name){
				let data = table.checkStatus(table_name).data;
				if (data.length === 0) {
					Alert('未选中数据','info',1.5);
					return false;
				}
				var ids = [];
				var hasCheck = table.checkStatus(table_name)
				var hasCheckData = hasCheck.data
				if (hasCheckData.length > 0) {
					$.each(hasCheckData, function (index, element) {
						ids.push(element.id)
					})
				}
				ids=ids.join('|');
				return ids;
			}
            
            //初始化分类下拉菜单
            layui.dropdown.render({
                elem: '#settype',
                data: [
                    {volist name="type_list.data" id="v"}
                    {
                        title: "{$v.name}",
                        id: {$v.id}
                    },
                    {/volist}
                ],
                click: function(obj){
                    let ids=isSelect(table,$table_name);
                    if(ids){
                        confirmed('确定设置为【'+obj.title+'】分类吗？',function(){
                            var url="{:U('cloth.temp/setValue')}";
                            var data={
                                type:'settype',
                                tid:obj.id,
                                ids:ids,
                            };
                            $.post(url,data,function(res){
                            	if(res.code==200){
                            		Alert('修改成功！','success',1);
                                    table.reload($table_name)
                            	}else{
                            		Alert(res.msg,'error',3);
                            	}
                            });
                        });
                    }else{
                        return false;
                    }
                }
            });
			
			//复制产品
			function copyCloth(ids){
				var url="{:U('cloth.temp/copyCloth')}";
				var data={
					ids:ids
				};
				$.post(url,data,function(res){
					if(res.code==200){
						if(res.data.status==1){
							load_hide();
							Alert(res.msg,'success',1);
							table.reload($table_name);
						}else{
							load_hide();
							Alert(res.msg,'error',3);
						}
					}else{
						load_hide();
						Alert(res.msg,'error',3);
					}
				});
			}
			
			// 筛选分类
			$(".type-box a").click(function(){
				let id=$(this).attr('data-id');
				$(".type-box a").removeClass('pear-btn-primary');
				$(this).addClass('pear-btn-primary');
				table.reload('dataTable', {
					where:{
						tid:id,
					},
					page:{curr: 1}
				})
				
				return false;
			});
			
        })		
    </script>
	{$LOAD_STYLE.bottom|raw}
	</body>
</html>
